package com.songlanyun.modules.userbank.controller.api;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.annotation.RepeatSubmit;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.userbank.entity.UserBank;
import com.songlanyun.modules.userbank.model.dto.UserBankDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.userbank.entity.UserBank;
import com.songlanyun.modules.userbank.service.UserBankService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;



/**
 * 会员的收货地址表
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-11 14:49:27
 */
@RestController
@RequestMapping("api/userbank")
public class UserBankApiController extends AbstractApiController {
    @Autowired
    private UserBankService userbankService;

    /**
     * 获取会员的收货地址
     */
    @RequestMapping("/list")
    public R list(){
        List<UserBank> list = userbankService.mybankList(getUserId(true));
        return R.ok().put("list", list);
    }


    /**
     * 获取会员的收货地址按id
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        UserBank data = userbankService.getByUserIdAndId(getUserId(true),id);
        return R.ok().put("data", data);
    }

    /**
     * 会员创建收货地址
     */
    @PostMapping("/save")
    @RepeatSubmit(value = "5")
    public R save(@RequestBody UserBankDTO dto){
        UserBank data = userbankService.add(getUserId(true), dto);
        return R.ok().put("data",data);
    }

    /**
     * 会员修改收货地址
     */
    @RepeatSubmit(value = "5")
    @PutMapping("/update")
    public R update(@RequestBody UserBankDTO dto){
        UserBank data = userbankService.update(getUserId(true),dto);
        return R.ok().put("data",data);
    }

    /**
     * 设置收货地址为默认
     */
    @RepeatSubmit(value = "5")
    @PutMapping("/set-def/{id}")
    public R setDef(@PathVariable("id") Long id){
        UserBank data = userbankService.setDefault(getUserId(true),id);
        return R.ok().put("data",data);
    }

    /**
     * 删除收货地址
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id){
		userbankService.remove(getUserId(true),id);
        return R.ok();
    }

}
